#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll a[100010];
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	ll n1=0,n2=0;
	for(int i=1;i<=n;i++)
	{
		if(n1<a[i])
		{
			n2=n1;
			n1=a[i];
		}
		else if(n2<a[i])
		{
			n2=a[i];
		}
	}
	cout<<n1+n2;
	return 0;
}
